home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / satellit / vstsrc / message.c < prev    next >
C/C++ Source or Header  |  1995-01-30  |  17KB  |  496 lines

  1. /*
  2.  * %W% %E% %U%  [EXTREL_1.2]
  3.  *
  4.  * VersaTrack orbit calculations are based on those that appear in Dr. Manfred
  5.  * Bester's sattrack program (the Unix(tm) version, circa 1992).
  6.  *
  7.  * The data from which the maps where generated come from "xsat", an
  8.  * X-Windows program by David A. Curry (N9MSW).
  9.  *
  10.  * Site coordinates come from various sources, including a couple of
  11.  * World Almanacs, and also from both of the programs mentioned above.
  12.  *
  13.  * The following are authors' applicable copyright notices:
  14.  *
  15.  *                                                                               
  16.  * Copyright (c) 1992, 1993, 1994 Manfred Bester. All Rights Reserved.        
  17.  *                                                                           
  18.  * Permission to use, copy, modify, and distribute this software and its      
  19.  * documentation for educational, research and non-profit purposes, without   
  20.  * fee, and without a written agreement is hereby granted, provided that the  
  21.  * above copyright notice and the following three paragraphs appear in all    
  22.  * copies.                                                                    
  23.  *                                                                              
  24.  * Permission to incorporate this software into commercial products may be    
  25.  * obtained from the author, Dr. Manfred Bester, 1636 M. L. King Jr. Way,     
  26.  * Berkeley, CA 94709, USA.                                                   
  27.  *                                                                             
  28.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,  
  29.  * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF    
  30.  * THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED   
  31.  * OF THE POSSIBILITY OF SUCH DAMAGE.                                         
  32.  *                                                                             
  33.  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT       
  34.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABLITY AND FITNESS FOR A    
  35.  * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"       
  36.  * BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,  
  37.  * UPDATES, ENHANCEMENTS, OR MODIFICATIONS.                                   
  38.  *                                                                             
  39.  *                                                                             
  40.  * Copyright 1992 by David A. Curry                                            
  41.  *                                                                             
  42.  * Permission to use, copy, modify, distribute, and sell this software and its 
  43.  * documentation for any purpose is hereby granted without fee, provided that  
  44.  * the above copyright notice appear in all copies and that both that copyright
  45.  * notice and this permission notice appear in supporting documentation.  The  
  46.  * author makes no representations about the suitability of this software for  
  47.  * any purpose.  It is provided "as is" without express or implied warranty.   
  48.  *                                                                             
  49.  * David A. Curry, N9MSW                                                       
  50.  * Purdue University                                                           
  51.  * Engineering Computer Network                                                
  52.  * 1285 Electrical Engineering Building                                        
  53.  * West Lafayette, IN 47907                                                    
  54.  * davy@ecn.purdue.edu                                                         
  55.  *                                                                             
  56.  * VersaTrack Copyright (c) 1993, 1994 Siamack Navabpour. All Rights Reserved.
  57.  *
  58.  * Permission is hereby granted to copy, modify and distribute VersaTrack
  59.  * in whole, or in part, for educational, non-profit and non-commercial use
  60.  * only, free of charge or obligation, and without agreement, provided that
  61.  * all copyrights and restrictions noted herein are observed and followed, and
  62.  * additionally, that this and all other copyright notices listed herein
  63.  * appear unaltered in all copies and in all derived work.
  64.  *
  65.  * This notice shall not in any way void or supersede any of the other authors
  66.  * rights or privileges.
  67.  *
  68.  * VersaTrack IS PRESENTED FREE AND "AS IS", WITHOUT ANY WARRANTY OR SUPPORT.
  69.  * YOU USE IT AT YOUR OWN RISK. The author(s) shall not be liable for any
  70.  * direct, indirect, incidental, or consequential damage, loss of profits or
  71.  * other tangible or intangible losses or benefits, arising out of or related
  72.  * to its use. VersaTrack carries no warranty, explicit or implied, including
  73.  * but not limited to those of merchantablity and fitness for a particular
  74.  * purpose.
  75.  *
  76.  * Siamack Navabpour, 12342 Hunter's Chase Dr. Apt. 2114, Austin, TX 78729.
  77.  * sia@bga.com or sia@realtime.com.
  78.  */
  79.  
  80.  
  81. #pragma  check_stack(off)
  82.  
  83. #include <windows.h>
  84. #include <stdio.h>
  85. #ifdef _DEBUG_
  86. #include <stdarg.h>
  87. #include <string.h>
  88. #endif /* _DEBUG_ */
  89.  
  90. #include "vstdefs.h"
  91. #include "vsttype.h"
  92. #include "libxtrns.h"
  93. #include "resource.h"   /* make sure the one in this directory is used! */
  94.  
  95. char textbuf[BUFLEN];
  96. char tmpbuf[BUFLEN]; 
  97. char msgbuf[BUFLEN]; 
  98. char string[BUFLEN];
  99.  
  100. COLORREF BColors[16] = {
  101.     0x00000000, 0x0000007f, 0x00007f00, 0x00007f7f,
  102.     0x007f0000, 0x007f007f, 0x007f7f00, 0x007f7f7f,
  103.     0x00bfbfbf, 0x000000ff, 0x0000ff00, 0x0000ffff,
  104.     0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff
  105. };
  106.  
  107. HWND Gwnd;
  108. LOGBRUSH    BDrawBrush[NPAL];         /* All the colored brushes */
  109. HBRUSH      hBDrawBrush[NPAL];        /* All the colored brush handles*/
  110. COLORREF    BColors[NPAL];            /* colors we can use... */
  111. HINSTANCE   hInstDLL;
  112. static HICON hAsterisk, hQuestion;   /* Icon handles */
  113. #ifdef _DEBUG_
  114. void (*diag)(va_list, ...);
  115. #else /* _DEBUG_ */
  116. void diag(void) { }
  117. #endif /* _DEBUG_ */
  118.  
  119. RECT ClRect;
  120. #define NSCREENS 3
  121.  
  122. static char *cptitle[] = {
  123. "Sattrack Copyright (c) 1992, 1993, 1994 Manfred Bester. All Rights Reserved.",
  124.  
  125. "Xsat Copyright 1992 by David A. Curry",
  126.  
  127. "VersaTrack Copyright (c) 1993, 1994 Siamack Navabpour. All Rights Reserved.",
  128. };
  129.  
  130. static char *cppara1[] = {
  131. "Permission to use, copy, modify, and distribute this software and its \
  132. documentation for educational, research and non-profit purposes, without \
  133. fee, and without a written agreement is hereby granted, provided that the \
  134. above copyright notice and the following three paragraphs appear in all \
  135. copies.",
  136.  
  137. "Permission to use, copy, modify, distribute, and sell this software and its \
  138. documentation for any purpose is hereby granted without fee, provided that \
  139. the above copyright notice appear in all copies and that both that copyright \
  140. notice and this permission notice appear in supporting documentation. The \
  141. author makes no representations about the suitability of this software for \
  142. any purpose.  It is provided \"as is\" without express or implied warranty.",
  143.  
  144. "Permission is hereby granted to copy, modify and distribute VersaTrack \
  145. in whole, or in part, for educational, non-profit and non-commercial use \
  146. only, free of charge or obligation, and without agreement, provided that \
  147. all copyrights and restrictions noted herein are observed and followed, and \
  148. additionally, that this and all other copyright notices and accompanying \
  149. paragraphs listed herein appear unaltered in all copies and in all derived \
  150. work.",
  151. };
  152.  
  153. static char *cppara2[] = {
  154. "Permission to incorporate this software into commercial products may be \
  155. obtained from the author, Dr. Manfred Bester, 1636 M. L. King Jr. Way, \
  156. Berkeley, CA 94709, USA.",
  157.  
  158. "David A. Curry, N9MSW, Purdue University, Engineering Computer Network, \
  159. 1285 Electrical Engineering Building, West Lafayette, IN 47907. \
  160. davy@ecn.purdue.edu",
  161.  
  162. "This notice shall not in any way void or supersede any of the other authors \
  163. rights or privileges.",
  164. };
  165.  
  166. static char *cppara3[] = {
  167. "IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, \
  168. SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF \
  169. THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED \
  170. OF THE POSSIBILITY OF SUCH DAMAGE.",
  171. " ",
  172. "Author can be contacted at the following address: 12342 Hunter's Chase Dr. \
  173. #2114, Austin, TX 78729. sia@realtime.com",
  174. };
  175.  
  176. static char *cppara4[] = {
  177. "THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT \
  178. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A \
  179. PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN \"AS IS\" \
  180. BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, \
  181. UPDATES, ENHANCEMENTS, OR MODIFICATIONS.",
  182.  
  183. " ",
  184.  
  185. "VersaTrack IS PRESENTED FREE AND \"AS IS\", WITHOUT ANY WARRANTY OR SUPPORT. \
  186. YOU USE IT AT YOUR OWN RISK. The author(s) shall not be liable for any \
  187. direct, indirect, incidental, or consequential damage, loss of profits or \
  188. other tangible or intangible losses or benefits, arising out of or related \
  189. to its use. VersaTrack carries no warranty, explicit or implied, including \
  190. but not limited to those of merchantablity and fitness for a particular \
  191. purpose.",
  192. };
  193.  
  194. static BOOL CALLBACK
  195. UserMsgProc(hwnd, message, wParam, lParam)
  196. HWND hwnd;
  197. UINT message;
  198. WPARAM wParam;
  199. LPARAM lParam;
  200. {
  201.     int action;
  202.     POINT *p;
  203.     HDC hdc;
  204.         
  205.     switch(message) {
  206.     case WM_INITDIALOG:
  207.         p = DialogPos(hwnd);
  208.         SendDlgItemMessage(hwnd, IDC_MSGTEXT, WM_SETTEXT, (WPARAM) 0, (LPARAM) msgbuf);
  209.         SendDlgItemMessage(hwnd, IDC_MSGTEXT, WM_SETFOCUS, (WPARAM)
  210.             GetParent(hwnd), (LPARAM) 0);
  211.         SetWindowPos(hwnd, HWND_TOPMOST, (int)p->x, (int)p->y, 0, 0,
  212.             SWP_NOSIZE|SWP_SHOWWINDOW);
  213.         hdc = GetDC(hwnd);
  214.         DrawIcon(hdc, 12, 17, hAsterisk);
  215.         ReleaseDC(hwnd, hdc);
  216.         return TRUE;
  217.  
  218.     case WM_COMMAND:
  219.         action = LOWORD(wParam);
  220.         if (action == IDOK) {
  221.             EndDialog(hwnd, wParam);
  222.             return TRUE;
  223.         }
  224.         break;
  225.  
  226.     case WM_CTLCOLORDLG:
  227.     case WM_CTLCOLORSTATIC:
  228.         SetTextColor((HDC)wParam, BColors[0]);
  229.         SetBkColor((HDC)wParam, BColors[14]);
  230.         return (BOOL) hBDrawBrush[14];
  231.  
  232.     default:
  233.         break;
  234.     }
  235.  
  236.     return FALSE;
  237. }
  238.  
  239.  
  240. static BOOL CALLBACK
  241. YesNoProc(hwnd, message, wParam, lParam)
  242. HWND hwnd;
  243. UINT message;
  244. WPARAM wParam;
  245. LPARAM lParam;
  246. {
  247.     int action;
  248.     POINT *p;
  249.     HDC hdc;
  250.  
  251.     switch(message) {
  252.     case WM_INITDIALOG:
  253.         p = DialogPos(hwnd);
  254.         SendDlgItemMessage(hwnd, IDC_YESNOTEXT, WM_SETTEXT, 0, (LPARAM) msgbuf);
  255.         SendMessage(hwnd, DM_SETDEFID, (WPARAM) IDOK, (LPARAM) 0);
  256.         SetWindowPos(hwnd, HWND_TOPMOST, (int)p->x, (int)p->y, 0, 0,
  257.             SWP_NOSIZE|SWP_SHOWWINDOW);
  258.         hdc = GetDC(hwnd);
  259.         DrawIcon(hdc, 14, 20, hQuestion);
  260.         ReleaseDC(hwnd, hdc);
  261.         return TRUE;
  262.  
  263.     case WM_COMMAND:
  264.         action = LOWORD(wParam);
  265.         if (action == IDOK || action == IDCANCEL) {
  266.             EndDialog(hwnd, (LOWORD(wParam) == IDOK) ? TRUE : FALSE);
  267.             return TRUE;
  268.         }
  269.         break;
  270.  
  271.     case WM_CTLCOLORSTATIC:
  272.     case WM_CTLCOLORDLG:
  273.         SetTextColor((HDC)wParam, BColors[11]); /* was 15 */
  274.         SetBkColor((HDC)wParam, BColors[7]);    /* was 5 */
  275.         return (BOOL) hBDrawBrush[7];           /* was 5 */
  276.     }
  277.  
  278.     return FALSE;
  279. }
  280.  
  281. static int Cscreen;
  282.  
  283. BOOL CALLBACK
  284. CpyRightProc(hwnd, message, wParam, lParam)
  285. HWND hwnd;
  286. UINT message;
  287. WPARAM wParam;
  288. LPARAM lParam;
  289. {
  290.     POINT *p;
  291.         
  292.     switch(message) {
  293.     case WM_INITDIALOG:
  294.         p = DialogPos(hwnd);
  295.         if (Cscreen != NSCREENS-1)
  296.             SendDlgItemMessage(hwnd, IDOK, WM_SETTEXT, 0, (LPARAM) "More..."); 
  297.  
  298.         SendDlgItemMessage(hwnd, IDC_TITLE, WM_SETTEXT, 0,
  299.             (LPARAM) cptitle[Cscreen]);
  300.         SendDlgItemMessage(hwnd, IDC_PARA1, WM_SETTEXT, 0,
  301.             (LPARAM) cppara1[Cscreen]);
  302.         SendDlgItemMessage(hwnd, IDC_PARA2, WM_SETTEXT, 0,
  303.             (LPARAM) cppara2[Cscreen]);
  304.         SendDlgItemMessage(hwnd, IDC_PARA3, WM_SETTEXT, 0,
  305.             (LPARAM) cppara3[Cscreen]);
  306.         SendDlgItemMessage(hwnd, IDC_PARA4, WM_SETTEXT, 0,
  307.             (LPARAM) cppara4[Cscreen]);
  308.         SetWindowPos(hwnd, HWND_TOPMOST, (int)p->x, (int)p->y, 0, 0,
  309.             SWP_NOSIZE|SWP_SHOWWINDOW);
  310.         break;
  311.         
  312.     case WM_COMMAND:
  313.         if (LOWORD(wParam) == IDOK) {
  314.             EndDialog(hwnd, wParam);
  315.             return TRUE;
  316.         }
  317.         break;
  318.  
  319.     case WM_CTLCOLORDLG:
  320.     case WM_CTLCOLORSTATIC:
  321.         SetTextColor((HDC)wParam, BColors[0]);
  322.         SetBkColor((HDC)wParam, BColors[8]);
  323.         return (BOOL) hBDrawBrush[8];
  324.     }
  325.     
  326.     return FALSE;
  327. }
  328.  
  329. main() { return 0; }
  330.  
  331.  
  332. WINAPI
  333. DBReadInit(HINSTANCE hinsdll, DWORD reason, LPVOID reserved)
  334. {
  335.     int i;
  336. #ifdef _DEBUG_
  337.     extern void ConsClose();
  338. #endif
  339.                 
  340.     if (reason == DLL_PROCESS_ATTACH) {
  341.         HDC hdc;
  342.  
  343.         hInstDLL = hinsdll;
  344. #ifdef _DEBUG_
  345.         diag = DebugFunc;
  346.         diag("DBREAD.DLL: Debug Console Opened.\n");
  347. #endif /* _DEBUG_ */
  348.         hdc = GetDC(NULL);
  349.         for (i=0; i < 16; i++) {
  350.                if (hdc)
  351.                 BColors[i] = GetNearestColor(hdc, BColors[i]);
  352.             BDrawBrush[i].lbStyle   = BS_SOLID;
  353.             BDrawBrush[i].lbHatch   = 0;
  354.             BDrawBrush[i].lbColor   = BColors[i];
  355.             hBDrawBrush[i] = CreateBrushIndirect(&BDrawBrush[i]);
  356.         }
  357.         ReleaseDC(NULL, hdc);
  358.         while (ShowCursor(FALSE) >=0 ) ;  /* remove anomallous show states */
  359.         ShowCursor(TRUE);
  360.         hAsterisk = LoadIcon(NULL, MAKEINTRESOURCE(IDI_ASTERISK));
  361.         hQuestion = LoadIcon(NULL, MAKEINTRESOURCE(IDI_QUESTION));
  362.     }
  363.     else if (reason == DLL_PROCESS_DETACH) {
  364.         for (i=0; i<16; i++) {
  365.             if (hBDrawBrush[i])
  366.                 DeleteObject(hBDrawBrush[i]);
  367.         }
  368. #ifdef _DEBUG_
  369.         ConsClose();
  370. #endif /* _DEBUG_ */
  371.     }
  372.     return TRUE;
  373. }
  374.  
  375.  
  376. BOOL
  377. GetEditText(hwnd, ItemId, buf, maxlen)
  378. HWND hwnd;
  379. int ItemId;
  380. char *buf;
  381. int maxlen;
  382. {
  383.     int i;
  384.     char tbuf[80], *cp;
  385.     
  386.     i = SendDlgItemMessage(hwnd, ItemId, (UINT)WM_GETTEXTLENGTH,
  387.             (WPARAM) 0, (LPARAM) 0);
  388.     if (i <=0 || i >= sizeof(tbuf)-1)
  389.         return FALSE;
  390.     else if (i > 0) {
  391.         SendDlgItemMessage(hwnd, ItemId, (UINT)WM_GETTEXT,
  392.             (WPARAM) i+1, (LPARAM) tbuf);
  393.         tbuf[i+1] = 0;
  394.         cp = stripLeadingSpace(tbuf);
  395.         strncpy(buf, cp, sizeof(tbuf));
  396.         stripTrailingSpace(buf);
  397.     }
  398.     return TRUE;
  399. }
  400.  
  401.  
  402. void
  403. usermsg(hwnd, msg)
  404. HWND hwnd;
  405. char *msg;
  406. {
  407.     strcpy(msgbuf,msg);
  408.  
  409.     if (IsIconic(hwnd)) {
  410.         OpenIcon(hwnd);
  411.         EnableWindow(hwnd, TRUE);
  412.     }
  413.     DialogBox(hInstDLL, MAKEINTRESOURCE(IDD_MESSAGE), hwnd, UserMsgProc);
  414. }
  415.  
  416.  
  417. BOOL
  418. yesno(hwnd, msg)
  419. HWND hwnd;
  420. char *msg;
  421. {
  422.     int r;
  423.     extern BOOL CALLBACK YesNoProc();
  424.  
  425.     strcpy(msgbuf,msg);
  426.  
  427.     if (IsIconic(hwnd)) {
  428.         OpenIcon(hwnd);
  429.         EnableWindow(hwnd, TRUE);
  430.     }
  431.     r = DialogBox(hInstDLL, MAKEINTRESOURCE(IDD_YESNO), hwnd, YesNoProc);
  432.     return r;
  433. }
  434.  
  435. void
  436. fatal(hwnd, s)
  437. HWND hwnd;
  438. char *s;
  439. {
  440.     char xbuf[256];
  441.     int e;
  442.     extern char *StrError(int);
  443.     
  444.     e = GetLastError();
  445.     sprintf(xbuf,"ERROR: %s (code %d) %s",s, e, StrError(e));
  446.     usermsg(hwnd, s);
  447.     ExitProcess(1);
  448. }
  449.  
  450.  
  451. void
  452. Copyright(int version, HWND hwnd)
  453. {
  454.     for (Cscreen = 0; Cscreen < NSCREENS; Cscreen++)
  455.         DialogBox(hInstDLL, MAKEINTRESOURCE(IDD_COPYRIGHT), hwnd, CpyRightProc);
  456. }
  457.  
  458.  
  459. POINT *
  460. DialogPos(cwnd)
  461. HWND cwnd;    /* position cwnd in center of pwnd */
  462. {
  463.     HWND pwnd;
  464.     RECT pr,cr;
  465.     static POINT p;
  466.     int xmax, ymax;
  467.  
  468.     xmax = GetSystemMetrics(SM_CXSCREEN);
  469.     ymax = GetSystemMetrics(SM_CYSCREEN);
  470.     pwnd = GetParent(cwnd);
  471.  
  472.     GetClientRect(pwnd,&pr);
  473.     GetClientRect(cwnd,&cr);
  474.     p.x = p.y = 0;
  475.     ClientToScreen(pwnd,&p);    /* upper left corner of parent on screen */
  476.     if ((p.x < 20) || (p.x + (pr.right - pr.left)) > xmax+20) {
  477.         pr.left = 0;
  478.         pr.right = xmax;
  479.         p.x = 0;
  480.     }
  481.     if ((p.y < 20) || (p.y + (pr.bottom - pr.top)) > ymax+20) {
  482.         pr.top = 0;
  483.         pr.bottom = ymax;
  484.         p.y = 0;
  485.     }
  486.     p.x += ((pr.right - pr.left) - (cr.right - cr.left)) / 2;
  487.     p.y += ((pr.bottom - pr.top) - (cr.bottom - cr.top)) / 2;
  488.     return &p;
  489. }
  490.  
  491. int
  492. VSTLVersion()
  493. {
  494.     return VSTVERSION;
  495. }
  496.